package java_0530_map;

import java.util.*;

@SuppressWarnings({"all"})
public class MapFor {
    public static void main(String[] args) {
        Map map = new HashMap();
        map.put(1, "凯文");
        map.put(2, "爱莉希雅");
        map.put(3, "阿波尼亚");


        //第一组：先取出所有的Key ，通过key取出对应的Value
        System.out.println("===============第一组==================");
        Set keyset = map.keySet();
        //(1)增强For
        for (Object key : keyset) {
            System.out.println(key+"-"+map.get(key));
        }

        //(2)迭代器
        Iterator iterator = keyset.iterator();
        while (iterator.hasNext()) {
            Object next = iterator.next();
            System.out.println(next+"-"+map.get(next));
        }

        //第二组：把所有的values取出
        System.out.println("===============第二组==================");
        Collection values = map.values();
        //这里可以使用所有的Collection使用的遍历方法
        //(1)增强for循环
        for (Object value :
                values) {
            System.out.println(value);
        }

        //(2)迭代器

        Iterator iterator2 = values.iterator();
        while (iterator2.hasNext()) {
            Object next = iterator2.next();
            System.out.println(next);
        }

        //第三组：通过EntrySet来获k-v
        System.out.println("===============第三组==================");
        Set entrySet = map.entrySet();//EntrySet<Map.Entry<K,V>>
        //(1)增强for
        for (Object entry : entrySet) {
            //将entry 转成Map.Entry
            Map.Entry m = (Map.Entry) entry;
            System.out.println(m.getKey() + "-" + m.getValue());
        }
    }
}
